package com.guxuede.mina.codefactory;

import java.nio.charset.Charset;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

public class HttpCodecFactory implements ProtocolCodecFactory{
	
	private final HttpEncoder httpEncoder;
	private final HttpDecoder httpDecoder;
	
	public HttpCodecFactory() {
		this(Charset.defaultCharset());
	}
	
	public HttpCodecFactory(Charset charSet) {
		httpEncoder=new HttpEncoder(charSet);
		httpDecoder=new HttpDecoder(charSet);
	}
	
	@Override
	public ProtocolDecoder getDecoder(IoSession arg0) throws Exception {
		return httpDecoder;
	}

	@Override
	public ProtocolEncoder getEncoder(IoSession arg0) throws Exception {
		return httpEncoder;
	}

}
